<?php
/**
 * @author bedirhan
 */
class PPopulator {

    public static function getTargetDate($currentDate){
        $timestamp = strtotime($currentDate);

        if(isset($_GET["nextDay"])){
            self::addDayToDate($timestamp);
            // reset set index
            $setIndex = 0;
        }
        else if(isset($_GET["prevDay"])){
            self::addDayToDate($timestamp, -1);
            // reset set index
            $setIndex = 0;
        }

        // update and store the current date
        $targetDate = date("Y-m-d", $timestamp);

        return $targetDate;
    }

    public static function getSetIndex($setIndex){

        if(isset($_GET["nextSet"]))
            $setIndex = $setIndex + 1;
        else if(isset($_GET["prevSet"])){
            if($setIndex > 0 )
                $setIndex = $setIndex - 1;
        }

        return $setIndex;
    }

    private static function addDayToDate(&$timestamp, $totalDays=1){
        $thePHPDate = getdate($timestamp);
        $thePHPDate['mday'] = $thePHPDate['mday'] + $totalDays;
        $timestamp = mktime($thePHPDate['hours'], $thePHPDate['minutes'], $thePHPDate['seconds'], $thePHPDate['mon'], $thePHPDate['mday'], $thePHPDate['year']);
    }
}
?>
